from src.generator.generator import Generator
from src.game.block.block import Block
from src.storage.pso import PSO
from src.game.entity.player import EntityPlayer
from mods.entities.entities import EntitySpawner
from src.game.entity.mob import EntityMob
import random

class FlatWorldGenerator(Generator):

    @staticmethod
    def generate(width, height):
        worlddata = []
        for row in range(height):
            for col in range(width):
                block = PSO()
                typ = "dirt"
                Block(col,row, typ).writeToPSO(block)
                worlddata.append(block.getData())



        entitydata = []
        spawn = PSO()
        entity = EntityPlayer()
        entity.x = width/2
        entity.y = height/2 - 1
        entity.writeToPSO(spawn)
        entitydata.append(spawn.getData())

        spawnerData = PSO()
        spawner = EntitySpawner()
        spawner.x = width / 2 - 3
        spawner.y = height / 2 - 1
        spawner.writeToPSO(spawnerData)
        entitydata.append(spawnerData.getData())
        
        """
        for i in range(100):
            mobData = PSO()
            mob = EntityMob()
            mob.x = random.randint(0, width - 1)
            mob.y = random.randint(0, height - 1)
            mob.writeToPSO(mobData)
            entitydata.append(mobData.getData())
            
        mobData = PSO()
        mob = EntityMob()
        mob.x = width / 2 + 10
        mob.y = height / 2 - 1
        mob.writeToPSO(mobData)
        entitydata.append(mobData.getData())
        """ 
        
        data = PSO()
        data.set("blocks", worlddata)
        data.set("entities", entitydata)
        return data
